
import DrawBase from "./DrawBase";
const {ccclass, property} = cc._decorator;
//涂抹单个
@ccclass
export default class DrawOne extends DrawBase {
    //刷子 
    @property(cc.Node)
    shuaZi: cc.Node = null;

    //刷子 
    @property(sp.Skeleton)
    shuaZiSk: sp.Skeleton = null;

    //效果 
    @property(cc.Node)
    effectNode: cc.Node = null;

    _offset = cc.v2(0,0);
    start(){
        //@ts-ignore
        this.graphics = this.mask._graphics;  
        this.reset();
        this.generateKeyPoints();
    };

    _touchStart(event,offset){
        this._offset = offset;
        if(this.shuaZiSk){
            this.shuaZiSk.setAnimation(0,"animation",true);
        }
        let real_x = this.shuaZi.x - this.mask.node.x;
        let real_y = this.shuaZi.y - this.mask.node.y;
        this._lastLoc = cc.v2(real_x, real_y);
        let worldPoint = event.touch.getLocation();
        let localPoint = this.shuaZi.parent.convertToNodeSpaceAR(worldPoint);
        this.shuaZi.x = localPoint.x + offset.x;
        this.shuaZi.y = localPoint.y + offset.y;
    };
    _touchMove(event){
        // let delta = event.touch.getDelta();
        // this.shuaZi.x += delta.x;
        // this.shuaZi.y += delta.y;
        let worldPoint = event.touch.getLocation();
        let localPoint = this.shuaZi.parent.convertToNodeSpaceAR(worldPoint);
        this.shuaZi.x = localPoint.x + this._offset.x;
        this.shuaZi.y = localPoint.y + this._offset.y;
        let real_x = this.shuaZi.x - this.mask.node.x;
        let real_y = this.shuaZi.y - this.mask.node.y;
        this.drawLine(cc.v2(real_x, real_y));
    };

    _touchEnd(callback:Function){
        if(this.shuaZiSk){
            this.shuaZiSk.setAnimation(0,"moren",false);
        }
        let done = this.checkKeyPoints();
        if (done) {
            callback && callback();
            if(this.effectNode){
                this.effectNode.active = true;
            }
            this.mask.node.active = false;
        }
    };
}
